print('欢迎使用Jian Recorder')
print('正在加载程序中')
from pynput.keyboard import GlobalHotKeys,Controller
import functions
print('\033[32m加载完成\033[0m')

is_in_func=False
keyboard_controller=Controller()
information=functions.terminal_2_get_information()
settings=functions.settings

def print_information(func):
    def printed():
        print()
        func()
        print(information,end='')
    return printed

@print_information
def record():
    global is_in_func
    is_in_func=True
    functions.terminal_record()
    is_in_func=False

@print_information
def play():
    global is_in_func
    is_in_func=True
    functions.terminal_play()
    is_in_func=False

@print_information
def optimize():
    global is_in_func
    is_in_func=True
    functions.terminal_optimize()
    is_in_func=False

@print_information
def set_settings():
    global is_in_func,information
    is_in_func=True
    functions.terminal_2_set_settings()
    information = functions.terminal_2_get_information()
    is_in_func=False

def system_exit():
    raise SystemExit

print(information)
with GlobalHotKeys({settings['record']:record,settings['play']:play,settings['optimize']:optimize,settings['set_settings']:set_settings,settings['exit']:system_exit}) as h:
    try:
        h.join()
    except KeyboardInterrupt:
        h.stop()
        raise SystemExit
